package com.yiban.demo.Order.Entity;

import lombok.Getter;

import java.util.Optional;

@Getter
public enum OrderStatus {
    /**
     * 从上到下分别为
     *  用户下单
     *  驿站方接收
     *  小车出发
     *  用户接收
     */
    ORDER(0,"已经下单"),
    WAITING(1,"等待配送"),
    DELIVERING(2,"正在配送"),
    END(3,"配送完成");

    private Integer statusCode;
    private String statusDesc;

    OrderStatus(Integer statusCode, String statusDesc) {
        this.statusCode = statusCode;
        this.statusDesc = statusDesc;
    }

    /**
     *
     * @param statusCode 状态码
     * @return 如果不存在就返回一个 {@code Optional.empty()}
     */
    public static Optional<OrderStatus> getStatus(int statusCode){
        for (OrderStatus value : OrderStatus.values()) {
            if (value.statusCode.equals(statusCode)){
                return Optional.of(value);
            }
        }
        return Optional.empty();
    }
}
